package com.chj.leetcode.tijie750to800;

public class Code780_ReachingPoints {
	public static boolean reachingPoints(int sx, int sy, int tx, int ty) {
		while (tx >= sx && ty >= sy) {
			if (tx > ty) {
				if (ty == sy)
					return (tx - sx) % ty == 0;
				tx %= ty;
			} else {
				if (tx == sx)
					return (ty - sy) % tx == 0;
				else
					ty %= tx;
			}
		}
		return tx == sx && ty == sy;
	}

	public static boolean reachingPoints02(int sx, int sy, int tx, int ty) {
		if (sx > tx || sy > ty) {
			return false;
		}
		if (sx == tx && sy == ty) {
			return true;
		}
		return reachingPoints(sx + sy, sy, tx, ty) || reachingPoints(sx, sx + sy, tx, ty);
	}

	public boolean reachingPoints04(int sx, int sy, int tx, int ty) {
		if (tx < sx || ty < sy) {
			return false;
		}
		if (tx == sx) {
			return (ty - sy) % sx == 0;
		}
		if (ty == sy) {
			return (tx - sx) % sy == 0;
		}

		if (tx > ty) {
			return reachingPoints(sx, sy, tx - ty, ty);
		} else if (tx < ty) {
			return reachingPoints(sx, sy, tx, ty - tx);
		}

		return false;
	}

//	http://www.noteanddata.com/leetcode-780-Reaching-Points-java-solution-note.html
	public static void main(String[] args) {
		{
			System.out.println(reachingPoints(1, 1, 3, 5));
		}

		{
			System.out.println(reachingPoints(1, 1, 2, 2));
		}

		{
			System.out.println(reachingPoints(1, 1, 1, 1));
		}
	}
}
